package com.doyens.reggie.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.doyens.reggie.commons.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

@Slf4j
@Component
public class MyMetaObjecthandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {//添加填充方法
        log.info("添加时填充");
        //createTime  当前时间
        metaObject.setValue("createTime", LocalDateTime.now());
        //updateTime  当前时间
        metaObject.setValue("updateTime", LocalDateTime.now());
        //createUser  当前登录用户的id
        metaObject.setValue("createUser", BaseContext.getCurrentId());//request--> session--->emp--->id
        //updateUser  当前登录用户的id
        metaObject.setValue("updateUser",  BaseContext.getCurrentId());
    }

    @Override
    public void updateFill(MetaObject metaObject) { //修改填充的方法
        log.info("修改时填充");
        //updateTime
        //updateUser
        //updateTime  当前时间
        metaObject.setValue("updateTime", LocalDateTime.now());
        //updateUser  当前登录用户的id
        metaObject.setValue("updateUser",  BaseContext.getCurrentId());
    }
}
